//
// api.js
// vue3-element-admin
//
// Created by 区区电脑 on 2023/04/11.
//


import request from "@/request"

// 添加
export function AddComputerInfo(data = {}) {
    return request({url: '/api/Computer/AddComputerInfo', method: 'post', data})
}

// 删除
export function DeleteComputerInfo(params = {}) {
    return request({url: '/api/Computer/DeleteComputerInfo', method: 'delete', params})
}

// 修改
export function UpdateComputerInfo(data = {}) {
    return request({url: '/api/Computer/UpdateComputerInfo', method: 'put', data})
}

/**
 * 详情
 * @param params
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function GetOneComputer(params = {}) {
    return request({url: '/api/Computer/GetOneComputer', method: 'get', params})
}

/**
 * 分页
 * @param params
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function GetComputerPageList(params = {}, data = {}) {
    return request({url: '/api/Computer/GetComputerPageList', method: 'post', params, data})
}



/**
 * 设备列表
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function GetDeviceList(data = {}) {
    return request({url: '/api/Device/GetDeviceList', method: 'post', data})
}

/**
 * 程序列表
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function GetProgramList(data = {}) {
    return request({url: '/api/Program/GetProgramList', method: 'post', data})
}

/**
 * 授权
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function CreateDeviceLicense(data = {}) {
    return request({url: '/api/Computer/CreateDeviceLicense', method: 'post', data})
}

/**
 * 下载License
 * @param params
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function DownloadLicense(data = {}, fileName) {
    return request({url: "/api/Computer/DownloadLicense", method: "post", data, responseBlob: true}).then((res) => {
        if (res.data) {
            const downloadUrl = URL.createObjectURL(res.data);
            const a = document.createElement("a");
            a.download = `${fileName}`;
            a.href = downloadUrl;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            window.URL.revokeObjectURL(downloadUrl);
            return {
                success: true,
            }
        } else {
            return {
                success: false,
            }
        }
    })
}


/**
 * 审核
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function UpdateComputerCanUse(data) {
    return request({url: "/api/Computer/UpdateComputerCanUse", method: "put", data})
}
/**
 * 查询打印模板
 * @param params
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function GetProgramReportPageList(params = {}, data = {}) {
    return request({url: '/api/ProgramReport/GetProgramReportPageList', method: 'post', params, data})
}